local socket = require('socket')

local host = 'www.w3.org'
local port = 80
local msgSend="GET /standards/xml/schema HTTP/1.1\r\n" 
            .."Host: www.w3.org\r\n\r\n"

local count = 0
local body =''

local conn = socket.connect(host, port)
conn:send(msgSend) 

while true do
  local s, status, partial = conn:receive()
  count = count + #(s or partial)
  -- print ("type(s)=" .. type(s))
  -- print ("type(status)=" .. type(status))
  -- print ("type(partial)=" .. type(partial))
  if status == "closed" then
    break
  end
  print (s)
  body = body .. s  -- lost \r\n
end

conn:close()
print(count)
-- print(body)




--[[
install socket
  luarocks install luasocket
  this will install to /usr/local/lib/luarocks/

http server:
  while true; do echo -e "HTTP/1.1 200 OK\r\n\r\nhello" | nc -l 32768; done

socket api
  http://w3.impa.br/~diego/software/luasocket/reference.html
--]]

